package com.zxy.cover.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.zxy.cover.entity.CoverEntity;
import com.zxy.cover.service.CoverService;
import com.zxy.common.utils.PageUtils;
import com.zxy.common.utils.R;



/**
 * 求房表
 *
 * @author zb
 * @email sunlightcs@gmail.com
 * @date 2022-04-26 15:07:03
 */
@RestController
@RequestMapping("cover/cover")
@CrossOrigin
public class CoverController {
    @Autowired
    private CoverService coverService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = coverService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		CoverEntity cover = coverService.getById(id);

        return R.ok().put("cover", cover);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody CoverEntity cover){
        cover.setStart( 0 );
		coverService.save(cover);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody CoverEntity cover){
        Date date = new Date();
        cover.setUpdatedAt( date );
        coverService.updateById(cover);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
        coverService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

    /**
     * 单删除
     */
    @RequestMapping("/deletes/{id}")
    public R deletes(@PathVariable("id") Integer id){
        CoverEntity coverEntity = coverService.getById( id );
        Date date = new Date();
        coverEntity.setDeletedAt( date );
        coverEntity.setStart( 1 );
        coverService.updateById(coverEntity);
        return R.ok();
    }

}
